package cn.ywang.current.demo;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

/**
 * @author BeatificWang
 * @date 2019/7/30 22:33
 */
public class ConditionSignal extends Thread {
	private Lock lock;

	private Condition condition;

	public ConditionSignal(Lock lock, Condition condition) {
		this.lock = lock;
		this.condition = condition;
	}


	@Override
	public void run() {
		try {
			this.lock.lock();
			String threadName = Thread.currentThread().getName();
			System.out.println("begin:" + threadName);
			this.condition.signal();
			System.out.println("end:" + threadName);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			this.lock.unlock();
		}
	}
}
